package threads;

import gui.Supervisor;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class ThreadPelea extends Thread
{
	private Supervisor sup;
	private boolean terminar;
	private JLabel[][] enConflicto;
	
	
	public ThreadPelea(Supervisor s)
	{
		sup = s;
		terminar = false;
		enConflicto = new JLabel[5][2];
	}
	
	public void run()
	{
		while(!terminar)
		{
			int fila = 0;
			while(fila < 5)
			{
				if(enConflicto[fila][0] != null && enConflicto[fila][1] != null)
					sup.atacarEnemigo(enConflicto[fila][1],enConflicto[fila][0]);
				fila++;
			}
			try {
				Thread.sleep(3000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	public void terminar()
	{
		terminar = true;
	}
	
	public void enConflictoEnemigo(int fila, JLabel label)
	{
		enConflicto[fila][1] = label;
		ImageIcon imagen = new ImageIcon(getClass().getClassLoader().getResource(label.getText()+"1.gif"));
		label.setBounds(label.getX(), label.getY(), imagen.getIconWidth(), label.getHeight());
		label.setIcon(imagen);
	}
	
	public void enConflictoTorre(int fila, JLabel label)
	{
		enConflicto[fila][0] = label;
	}
	
	public void murio(int fila)
	{
		enConflicto[fila][0] = null;
		enConflicto[fila][1] = null;
	}
	
}